package com.fansl.allround.upms.api.feign.fallback;

import com.fansl.allround.common.core.bean.UserInfo;
import com.fansl.allround.common.core.constant.enums.OauthTypeEnum;
import com.fansl.allround.upms.api.dto.BindSocialInfoDTO;
import com.fansl.allround.upms.api.dto.SysSocialUserDTO;
import com.fansl.allround.upms.api.dto.UnbindSocialInfoDTO;
import com.fansl.allround.upms.api.feign.RemoteUserService;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author fansl
 * @Description: TODO
 * @date 2019/8/9 16:26
 */
@Slf4j
@Component
public class RemoteUserServiceFallbackImpl implements RemoteUserService {
    @Setter
    private Throwable cause;
    /**
     * 通过用户名查询用户、角色信息
     *
     * @param username 用户名
     * @param from     调用标志
     * @return R
     */
    @Override
    public UserInfo info(String username, String from) {
        log.error("feign 查询用户信息失败:{}", username, cause);
        return null;
    }

    /**
     * 通过社交账号查询用户、角色信息
     *
     * @param openid
     * @param oauthType 认证类型
     * @param from 调用标志
     * @return
     */
    @Override
    public UserInfo social(String openid, OauthTypeEnum oauthType,String from) {
        log.error("feign 查询用户信息失败:{}", openid, cause);
        return null;
    }

    /**
     * 通过手机号查询用户、角色信息
     *
     * @param mobile 手机号
     * @param from   调用标志
     * @return R
     */
    @Override
    public UserInfo mobile(String mobile, String from) {
        log.error("feign 查询用户信息失败:{}", mobile, cause);
        return null;
    }

    /**
     * 注册社交用户
     *
     * @param socialUser
     * @param from 调用标志
     * @return
     */
    @Override
    @SneakyThrows
    public UserInfo createSocialUser(SysSocialUserDTO socialUser, String from) {
        ObjectMapper mapper = new ObjectMapper();
        log.error("feign 注册社交用户失败:{}",mapper.writeValueAsString(socialUser) , cause);
        return null;
    }

    /**
     * 绑定第三方应用
     *
     * @param socialInfo
     * @param from
     * @return
     */
    @Override
    @SneakyThrows
    public Boolean bindSocialInfo(BindSocialInfoDTO socialInfo, String from) {
        ObjectMapper mapper = new ObjectMapper();
        log.error("feign 绑定第三方应用失败:{}",mapper.writeValueAsString(socialInfo) , cause);
        return null;
    }

    /**
     * 解绑第三方应用
     *
     * @param socialInfo
     * @return
     */
    @Override
    @SneakyThrows
    public Boolean unbindSocialInfo(UnbindSocialInfoDTO socialInfo, String from) {
        ObjectMapper mapper = new ObjectMapper();
        log.error("feign 解绑第三方应用失败:{}",mapper.writeValueAsString(socialInfo) , cause);
        return null;
    }
}
